package com.ruicar.afs.cloud.channel.channelworkflow.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruicar.afs.cloud.channel.channelworkflow.entity.WorkTaskCreated;
import com.ruicar.afs.cloud.channel.channelworkflow.mapper.WorkTaskCreatedMapper;
import com.ruicar.afs.cloud.channel.channelworkflow.service.WorkTaskCreatedService;
import com.ruicar.afs.cloud.channel.common.enums.ChannelAfsFlowEnum;
import com.ruicar.afs.cloud.common.core.enums.AfsEnumUtil;
import com.ruicar.afs.cloud.workflow.api.dto.flowprocess.response.FlowCmdBean;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author mingzhi.li
 */
@Service
public class WorkTaskCreatedServiceImpl extends ServiceImpl<WorkTaskCreatedMapper, WorkTaskCreated> implements WorkTaskCreatedService {
    /**
     * 渠道审批流程审批意见返回
     *
     * @param approve
     * @return
     */
    @Override
    public FlowCmdBean channelApprove(String approve, List<FlowCmdBean> cmdList) {
        FlowCmdBean bean = new FlowCmdBean();
        if (cmdList != null && cmdList.size() > 0) {
            for (int i = 0; i < cmdList.size(); i++) {
                if (approve.equals(AfsEnumUtil.key(AfsEnumUtil.key(ChannelAfsFlowEnum.CHANNEL_SUBMIT)))) {
                    if (AfsEnumUtil.desc(ChannelAfsFlowEnum.CHANNEL_SUBMIT).equals(cmdList.get(i).getCmdDis())) {
                        bean = cmdList.get(i);
                        break;
                    }
                } else if (approve.equals(AfsEnumUtil.key(AfsEnumUtil.key(ChannelAfsFlowEnum.CHANNEL_BACK)))) {
                    if (AfsEnumUtil.desc(ChannelAfsFlowEnum.CHANNEL_BACK).equals(cmdList.get(i).getCmdDis())) {
                        bean = cmdList.get(i);
                        break;
                    }
                } else if (approve.equals(AfsEnumUtil.key(AfsEnumUtil.key(ChannelAfsFlowEnum.CHANNEL_REFUSE)))) {
                    if (AfsEnumUtil.desc(ChannelAfsFlowEnum.CHANNEL_REFUSE).equals(cmdList.get(i).getCmdDis())) {
                        bean = cmdList.get(i);
                        break;
                    }
                }
            }
        }
        return bean;
    }

    @Override
    public FlowCmdBean affiliateApprove(String approve, List<FlowCmdBean> cmdList) {
        FlowCmdBean bean = new FlowCmdBean();
        if (cmdList != null && cmdList.size() > 0) {
            for (int i = 0; i < cmdList.size(); i++) {
                if (approve.equals(AfsEnumUtil.key(AfsEnumUtil.key(ChannelAfsFlowEnum.AFFILIATE_SUBMIT)))) {
                    if (AfsEnumUtil.desc(ChannelAfsFlowEnum.AFFILIATE_SUBMIT).equals(cmdList.get(i).getCmdDis())) {
                        bean = cmdList.get(i);
                        break;
                    }
                } else if (approve.equals(AfsEnumUtil.key(AfsEnumUtil.key(ChannelAfsFlowEnum.AFFILIATE_BACK)))) {
                    if (AfsEnumUtil.desc(ChannelAfsFlowEnum.AFFILIATE_BACK).equals(cmdList.get(i).getCmdDis())) {
                        bean = cmdList.get(i);
                        break;
                    }
                } else if (approve.equals(AfsEnumUtil.key(AfsEnumUtil.key(ChannelAfsFlowEnum.AFFILIATE_REFUSE)))) {
                    if (AfsEnumUtil.desc(ChannelAfsFlowEnum.AFFILIATE_REFUSE).equals(cmdList.get(i).getCmdDis())) {
                        bean = cmdList.get(i);
                        break;
                    }
                }
            }
        }
        return bean;
    }
}
